package org.wzl.todolisthelper.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component 
public class MyMetaObjectHandler implements MetaObjectHandler { 
     
    @Override 
    public void insertFill(MetaObject metaObject) { 
 
        Object createDate = getFieldValByName("createDate", metaObject); 
        if(null == createDate){ 
            // 该属性为空，可以进行填充 
            setFieldValByName("createDate", LocalDateTime.now(),metaObject); 
        } 
 
    }
 
    @Override 
    public void updateFill(MetaObject metaObject) { 
        this.strictUpdateFill(metaObject, "updateDate", LocalDateTime.class, LocalDateTime.now()); 
    } 
 
 
}